import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import VueAxios from 'vue-axios'
import VueLazyload from 'vue-lazyload'
import VueCookie from 'vue-cookie'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './assets/scss/reset.scss'
import './assets/scss/base.scss'
import './assets/scss/config.scss'
import './assets/scss/button.scss'

//根据前端的跨域方式做调整 /a/a:/api/a/b => /a/b(这是接口代理的)
axios.defaults.baseURL='/api';
axios.defaults.timeout=8000;
//接口错误拦截
axios.interceptors.response.use((response)=>{
  let res=response.data;//取得返回数据
  let path=location.hash;//获取hash路由
  if(res.status==0){//status=0表示返回成功
    return res.data;
  }else if(res.status==10){//status=10表示未登录
    if(path!='#/index'){//在首页的话就不跳转
      window.location.href='/#/login';//未登陆的话跳转地址
    }
    return Promise.reject(res)
  }else{
    this.$message({
      showClose: true,
      message:res.msg,
      type: 'warning'
    });
    return Promise.reject(res);
  }
})

Vue.config.productionTip = false
Vue.use(VueAxios,axios);
Vue.use(VueCookie);
Vue.use(VueLazyload, {
  loading: '/img/loading-svg/loading-bars.svg',
});
Vue.use(ElementUI);

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
